﻿@using Lavka.Core
@using Lavka.Models
@{LavkaDbEntities db = new LavkaDbEntities();}
<div id="menucontainer" >
        <ul id="menu" class="ui-corner-bottom">
            <li class="menu-item">@Html.ActionLink("Главная", "Index", "Home")</li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item"><a onclick="ShowMenuPopup('popupProducts');">Каталог товаров</a>
                    <ul id="popupProducts" class="unclicked">
                    <li>
                        
                    @{
                        <table class="menu-table">
                        <tr>
                            <td colspan="2"></td>
                        </tr>
                        <tr class="hovered">
                            <td>
                                <img src="@Url.Content("~/Content/images/ico-all-products.png")" alt="item.Name" class="x-small-image" />
                            
                            </td>
                            <td>
                                @Html.ActionLink("Все товары", "List", "Products", UrlParameter.Optional, null)
                            </td>
                        </tr>
                        @foreach (var item in CategoriesHelper.GetCategories(false, db))
                        {
                            <tr class="hovered">
                                <td>
                                    @if (!string.IsNullOrEmpty(item.Photo))
                                    {
                                        <img src="@Url.Content(item.Photo)" alt="item.Name" class="x-small-image" />
                                    }
                                </td>                            
                            
                                <td>
                                    @Html.ActionLink(item.Name, "Category", "Products", new { categoryId = item.CategoryId }, null)
                                </td>

                            </tr>
                        }
                        <tr><td colspan="2">&nbsp;</td></tr>
                        </table>
                    }

                    <div onclick="closeMenuItems()" class="menu-close-button" />

                    </li>
                    </ul>
            </li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item"><a onclick="ShowMenuPopup('popupViewed');">Просмотренные товары</a>
                <ul id="popupViewed" class="unclicked">
                    <li>
                        @if (ProductsHelper.ViewedProducts.Count > 0)
                        { 
                          
                           <table class="menu-table">
                           <tr><td colspan="2">&nbsp;</td></tr>
                            @foreach (Products p in Lavka.Core.ProductsHelper.ViewedProducts)
                            {
                                <tr class="hovered">
                                    <td>
                                        @if (!string.IsNullOrEmpty(p.Photo))
                                        {
                                            <img src="@Url.Content(p.Photo)" alt="@p.Name" class="x-small-image" />
                                        }
                                    </td>
                                    <td>
                                        @Html.ActionLink(p.Reference + " " + p.Name, "Details", "Products", new { id = p.ProductId }, null) 
                                    </td>
                                </tr>
                            }
                            <tr><td colspan="2">&nbsp;</td></tr>
                            </table>
                            
                            <div onclick="closeMenuItems()" class="menu-close-button" />
                        }
                    
                    </li>
                
                </ul>
            </li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item">@Html.ActionLink("Оплата", "Payment", "Home")</li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item">@Html.ActionLink("Доставка", "Delivery", "Home")</li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item">@Html.ActionLink("Контакты", "Contacts", "Home")</li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item">
            @if (CartHelper.Cart.Count > 0)
            {            
                <a onclick="ShowMenuPopup('popupCart');">Корзина<span style="color: green">(@CartHelper.Cart.Count)</span></a>
                <ul id="popupCart" class="unclicked">
                <li>
                    
                    @if (CartHelper.Cart.Count > 0)
                    {
                        <table class="menu-table">
                        <tr><td colspan="4" class="menu-make-order">
                            @Html.ActionLink("Оформить заказ", "Create", "Orders", UrlParameter.Optional, FormMethod.Get)
                        </td></tr>

                        <tr><td colspan="4"><hr/></td></tr>

                        @foreach (Products pc in CartHelper.Cart)
                        {
                            <tr class="hovered">
                                <td>
                                    @if (!string.IsNullOrEmpty(pc.Photo))
                                    {
                                        <img src="@Url.Content(pc.Photo)" alt="@pc.Name" class="x-small-image" />
                                    }
                                </td>
                                <td>
                                    @Html.ActionLink(pc.Reference + " " + pc.Name, "Details", "Products", new { id = pc.ProductId }, null) 
                                </td>
                                <td>

                                    @{
                                       var actionPrice = ActionsHelper.GetActionPrice(pc, db);
                                       if (!string.IsNullOrEmpty(actionPrice))
                                       {
                                                    <div class="menu-action-price">@pc.Price&nbsp;грн.</div>
                                                    <div class="menu-price">@actionPrice&nbsp;грн.</div>
                                       }
                                       else
                                       {
                                           <div class="menu-price">@ProductsHelper.GetProductPrice(pc, db)&nbsp;грн.</div>
                                       }    
                                    }
                                        
                                </td>
                                <td>
                                    <a href="/Orders/DeleteItem/@pc.ProductId">
                                    <img src="@Url.Content("~/Content/images/delete.png")" class="icon-small"/>
                                    </a>                                
                                </td>
                            </tr>
                        }

                        <tr><td colspan="4"><hr/></td></tr>

                        <tr style="height: 20px;">
                            <td style="text-align: right;">
                            </td>
                            <td style="text-align: right; padding-right: 5px;">
                                <div class="menu-price">Всего:</div>
                            </td>
                            <td style="text-align: left;">
                                <div class="menu-price">@string.Format("{0:0.00}", CartHelper.GetSumPrice(db))&nbsp;грн.</div>
                            </td>
                        </tr>

                        <tr><td colspan="3">&nbsp;</td></tr>
                        </table>
                        
                        <div onclick="closeMenuItems()" class="menu-close-button" />
                    } 
                    
                    
                </li>
                </ul>
            }
            else
            {
               <a>Корзина(0)</a>                               
            }
                
            </li>
            <li><img src="@Url.Content("~/Content/images/menu-item-devider.png")"></li>
            <li class="menu-item" style="padding-left: 10px;"><a onclick="ShowMenuPopup('popupSearch');">Поиск</a>
                <ul id="popupSearch" class="unclicked" style="right: 0px; width: 230px;">
                    <li>
                        @Html.Partial("SearchControl")

                        <div onclick="closeMenuItems()" class="menu-close-button" />
                    </li>
                </ul>
            </li>
        </ul>
</div>